package vip.xiaonuo.smzq.modular.user.controller;

import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import vip.xiaonuo.smzq.modular.user.entity.Role;
import vip.xiaonuo.smzq.modular.user.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 角色
 *
 * @author sqq
 * @since 2024-06-06
 */
@Api(tags = "角色")
@RestController
@RequestMapping("/user/role")
@Validated
public class RoleController {

    @Resource
    private IRoleService iRoleService;

    /**
     * 添加角色
     */
    @ApiOperation("添加角色")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid Role role) {
        iRoleService.save(role);
        return CommonResult.ok();
    }

    /**
     * 删除角色
     */
    @ApiOperation("删除角色")
    @PostMapping("/delete")
    public CommonResult<String> delete(@ApiParam(name = "pkid", value = "主键") @RequestParam String pkid) {
        iRoleService.removeById(pkid);
        return CommonResult.ok();
    }

    /**
     * 编辑角色
     */
    @ApiOperation("编辑角色")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid Role role) {
        iRoleService.updateById(role);
        return CommonResult.ok();
    }

    /**
     * 角色分页查询
     */
    @ApiOperation("角色分页查询")
    @GetMapping("/list")
    public CommonResult<Page<Role>> page() {
        return CommonResult.data(iRoleService.page(new Role()));
    }
}
